package com.cnzhy.config;

import com.google.common.collect.Lists;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Author: zhaoyan5
 * swagger配置
 */
@SpringBootConfiguration
@EnableSwagger2  //开启 swagger2
public class SwaggerConfig {

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                // RequestHandlerSelectors, 配置要扫描的包
                // basePackage(): 指定要扫描的包
                // any(): 扫描全部
                // none(): 都不扫描
                // withClassAnnotation : 扫描类上的注解, 参数是一个注解的反射对象
                // 例如：withClassAnnotation(RestController.class) 只扫描类上有@RestController的生成文档
                // withMethodAnnotation: 扫描方法上的注解, 参数是一个注解的反射对象
                .apis(RequestHandlerSelectors.basePackage("com.cnzhy"))
                // paths(): 过滤什么路径
//                .paths(PathSelectors.ant("/kuang/**"))
                .build();  //build
    }

    private ApiInfo apiInfo() {
        Contact contact = new Contact("zhaoyan", "www.zhaoyan5.com", "cnzhaoyan@foxmail.com");
        return new ApiInfo("API文档", "swagger 测试", "1.0", "urn:tos", contact, "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", Lists.newArrayList());
    }

}
